package com.hzy.admin.controller.system;

import com.hzy.admin.controller.ApiBaseController;
import com.hzy.admin.models.vo.system.SysRoleMenuFunctionVo;
import com.hzy.admin.models.vo.system.TableVo;
import com.hzy.admin.repository.entity.system.SysRole;
import com.hzy.admin.services.system.ISysRoleMenuFunctionService;
import com.hzy.admin.services.system.ISysRoleService;
import com.hzy.framework.ApiResult;
import com.hzy.framework.annotation.SystemAuthority;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 角色控制器
 *
 * @author hzy
 */
@Controller
@RequestMapping("/admin/system/role/function")
public class SysRoleMenuFunctionController extends ApiBaseController<ISysRoleMenuFunctionService> {
    private final ISysRoleService sysRoleService;

    public SysRoleMenuFunctionController(ISysRoleMenuFunctionService sysRoleMenuFunctionService,
                                         ISysRoleService sysRoleService) {
        super("bd024f3a-99a7-4407-861c-a016f243f222", sysRoleMenuFunctionService, "/system/rolemenufunction/");
        this.sysRoleService = sysRoleService;
    }

    /**
     * 列表页面
     *
     * @return
     */
    @SystemAuthority()
    @GetMapping("/index")
    public String index() {
        return this.view("index");
    }

    /**
     * 查询列表
     *
     * @param page   页码
     * @param size   页数
     * @param search 查询
     * @return json
     */
    @PostMapping("/list/{size}/{page}")
    @ResponseBody
    public ApiResult findList(@PathVariable Integer page, @PathVariable Integer size, @RequestBody SysRole search) {
        TableVo<Map<String,Object>> tableViewDto = this.sysRoleService.findList(page, size, search);
        return this.resultOk(tableViewDto);
    }

    /**
     * 保存数据
     *
     * @param vo 要保存数据
     * @return json
     */
    @PostMapping("/save")
    @ResponseBody
    public ApiResult save(@RequestBody SysRoleMenuFunctionVo vo) {
        return this.resultOk(this.service.insertOrUpdate(vo));
    }

    /**
     * 获取菜单功能树
     *
     * @param roleId
     * @return
     */
    @PostMapping("/getRoleMenuFunctionTree/{roleId}")
    @ResponseBody
    public ApiResult getRoleMenuFunctionTree(@PathVariable String roleId) {
        return this.resultOk(this.service.getRoleMenuFunctionTree(roleId));
    }

}
